#ifndef TRAIN_H
#define TRAIN_H

#include <QWidget>
#include <QLabel>
#include <QPushButton>
#include "global_def.h"
#include "tbfwidget.h"

#define LAYS 8

namespace Ui {
class Train;
}

class Train : public QWidget
{
    Q_OBJECT

public:
    explicit Train(QWidget *parent = nullptr);
    ~Train();
    void setPECUStatus(uint8_t car,uint8_t index, uint8_t stat);
    static Train* pThis;
    void setCabStat(int cab,uint8_t stat);
    void setTrainID(uint8_t id);
    void setLineID(uint8_t id);
    void setDirection(uint8_t dir);
    void setHSCBStat(uint8_t index, uint8_t stat);
    void setTracConvertStat(uint8_t index, uint8_t stat);
    void setTSKStat(uint8_t index, uint8_t stat);
    void setIdlingStat(uint8_t index, uint8_t stat);
    void setSlipingStat(uint8_t index, uint8_t stat);
    void setAuxConvertStat(uint8_t index, uint8_t stat);
    void setBatChargerStat(uint8_t index, uint8_t stat);
    void setServiceBrkStat(uint8_t car, uint8_t index, uint8_t stat);
    void setParkingBrakeStat(uint8_t index, uint8_t stat);
    void setAirCompressorStat(uint8_t index, uint8_t stat);
    void setEmDorStat(uint8_t index,uint8_t stat);
    void setSaloonDorStat(uint8_t car,uint8_t index,uint8_t stat);
    void setFireStat(uint8_t index, uint8_t value);
    void setPanStat(uint8_t index, uint8_t stat);
    void setIESStat(uint8_t index, uint8_t stat);
    void setACModeStat(uint8_t index,bool stat);
    void setEffDmd(bool tracTL,bool brkTL,bool FBTL,uint16_t value);
    void setDefaultStat();
    void setDisplayUnNormalStat();
    void setDisplayNormalStat();
signals:
    void GoToFirePage();
    void GoToPECUPage();
private:
    QList<QLabel*> m_lSaloonList;//车体
    QList<QLabel*> m_lCabinList;//司机室
    QList<QLabel*> m_lEmrDorList;//逃生门
    QList<QLabel*> m_lSaloonDorList[SaloonCnt];//客室门
    QList<QLabel*> m_lServiceBrake[SaloonCnt];//常用制动
    QList<QLabel*> m_lParkingBrakeList;//停放制动
    QList<QLabel*> m_lAuxConvertList;//辅助逆变器
    QList<QLabel*> m_lBatChargerList;//充电机
    QList<QLabel*> m_lTracConvertList;//牵引逆变器
    QList<QLabel*> m_lAirCompressList;//空压机
    QList<QLabel*> m_lTrainId;//车号
    QList<QLabel*> m_lPanList;//受电弓
    QList<QLabel*> m_lTSKList;//供电接触器
    QList<QLabel*> m_lHSCBList;//高断
    QList<QPushButton*> m_lPECUList;//乘客紧急对讲
    QList<QPushButton*> m_lFireList;//火灾
    QList<QLabel*> m_lSlipList;//滑行
    QList<QLabel*> m_lIdlingList;//空转
    QList<QLabel*> m_lDirectionList;//方向
    QList<QLabel*> m_lIESList;//三位置开关
    QList<QLabel*> m_lACModeList;//车间电源供电状态

private:
    QList<uint8_t> m_lPECUStatValue[SaloonCnt];
private:
    void InitSaloons();
    void InitCabins();
    void InitEmrDors();
    void InitDorNum();
    void InitSaloonDors();
    void InitServiceBrk();
    void InitParkingBrk();
    void InitAuxConverts();
    void InitBatChargers();
    void InitTracConverts();
    void InitAirCompressers();
    void InitTrainId();
    void InitPans();
    void InitTSKs();
    void InitHSCBS();
    void InitIES();
    void InitPECUs();
    void InitFires();
    void InitSlippings();
    void InitIdlings();
    void InitDirection();
    void InitDerails();
    void InitACMode();
    void SetPosition(QWidget* w, int car, uint8_t row, uint8_t col,uint8_t total, bool xReverse=false);
private:
    /*---------自定义部分----------*/
    uint m_nLeftSideSpaceX;//左侧空白
    uint m_nRightSideSpaceX;//右侧空白
    uint m_nSideSpaceY;//顶部空白
    uint m_nCabinWidth;//司机室宽度

    uint16_t m_nSaloonDorNumHeight;
    uint8_t m_nEmrDorWidth;
    uint8_t m_nEmrDorHeight;
    uint8_t m_nLabelSpaceX;//水平方向图标间隔
    /*---------自由变动部分----------*/
    uint m_nSalStartx;
    uint m_nSalStarty;
    uint m_nSaloonWidth;
    uint m_nSaloonHeight;

    uint m_nCabStartx;
    uint m_nCabStarty;

    uint m_nSaloonDorWidth;
    uint m_nSaloonDorHeight;

    uint16_t m_nLabelWidth;
    uint16_t m_nLabelHeight;
    uint16_t m_nSaloonDorNumWidth;

    float m_nLabelSpaceY;//竖直方向图标间隔
private:
    Ui::Train *ui;
    uint8_t m_nLineID=8;
    uint8_t m_nTrainID=0;
private:
    TBFWidget *tbfbar_;
};

#endif // TRAIN_H
